import { createRouter, createWebHistory} from 'vue-router'
import type {RouteRecordRaw} from 'vue-router'
import HomeView from '../views/HomeView.vue'

declare module 'vue-router'{
  interface RouteMeta{
    title:string,
    translate:string
  }
}
const routes:Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'login',
    alias:['/root','/root1'],//起别名
    meta:{
      title:'登录页面',
      translate:'animate__bounceIn'
    },
    // redirect:'/home',
    // route level code-splitting
    // this generates a separate chunk (About.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import('../components/Login.vue')
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView,
    meta:{
      title:'首页',
      translate:'animate__fadeInTopLeft'
    },
    children:[
      {
        path:'user1',
        components:{//多个页面
          default:()=>import('../components/TheWelcome.vue'),
          myname:()=>import('../components/TheWelcome.vue')
        }
      }
    ]
  }  
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  scrollBehavior:(to,from,savePosition)=>{
    // console.log(savePosition);
    if(savePosition){//路由滚动行为
      return savePosition
    }
    return {
      top:0
    }
  },
  routes
})

export default router
